<script setup name="finefood">
// import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { useStore } from 'vuex';
import { computed } from 'vue';
const store = useStore();
const route = useRoute();
// 轮播图
store.dispatch('home/updateHomePageBannerList');
const swiperList = computed(() => store.state.home.homepageBannerList);
// 二级分类请求
store.dispatch('category/updateCategoryList', route.path.split('/')[2]);
const CategoryList = computed(() => store.state.category.categoryList);
console.log(route);
const breadcrumb = computed(() => {
  return route.matched
    .map((item) => item.name !== '分类' ?
      { ...item, breadcrumbName: item.name } :
      { ...item, breadcrumbName: store.state.home.homepageHeadList.find((c) => route.params.id === c.id)?.name },
    );
});

</script>

<template>
  <div class="conter">
    <!-- 面包屑 -->
    <!-- <div class="crumbs">
      <el-breadcrumb separator=">">
        <el-breadcrumb-item
          v-for="item in breadcrumb"
          :key="item.name"
          :to="item"
        >
          {{ item.breadcrumbName }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div> -->
    <!-- 轮播图 -->
    <div class="slideshow wapper">
      <el-carousel :interval="3000" arrow="always" height="500px">
        <el-carousel-item v-for="item in swiperList" :key="item.id">
          <img :src="item.imgUrl" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- 分类 -->
    <div class="classify wapper">
      <h3>全部分类</h3>
      <div class="box" v-for="item of CategoryList.children" :key="item.id">
        <div><img :src="item.picture" /></div>
        <div>{{ item.name }}</div>
      </div>
    </div>
    <!-- 二级分类 -->
    <div class="reclassify wapper">
      <div class="boxone" v-for="item of CategoryList.children" :key="item.id">
        <span>
          查看全部
          <i>
            <el-icon>
              <ArrowRight />
            </el-icon>
          </i>
        </span>
        <h3>- {{ item.name }} -</h3>
        <p>温暖柔软，品质之选</p>
        <div class="vessel">
          <div class="boxtwo" v-for="item of item.goods" :key="item.id">
            <img :src="item.picture" alt="" />
            <p>{{ item.name }}</p>
            <p>{{ item.desc }}</p>
            <p>¥{{ item.price }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scope>
// 版心
.wapper {
  margin: 0 auto;
  width: 1240px;
}

// 容器
.conter {
  background-color: #f5f5f5;

  // 轮播图
  .slideshow {
    padding-top: 80px;
    padding-bottom: 20px;

    .el-carousel__button {
      border-radius: 50%;
      width: 10px;
      height: 10px;
      background-color: #fff;
    }
  }

  .crumbs {
    width: 80%;
    height: 100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    // outline: 1px solid red;
    padding-left: 20px;
  }

  // 分类
  .classify {
    height: 260px;
    background-color: #fff;

    h3 {
      margin: 0;
      font-size: 28px;
      color: #666;
      font-weight: 400;
      text-align: center;
      line-height: 100px;
    }

    .box {
      display: inline-block;
      text-align: center;
      padding-left: 70px;

      &:hover {
        color: #27ba9b;
        cursor: pointer;
      }
    }

    img {
      height: 100px;
      width: 100px;
    }
  }
}

// 二级分类
.reclassify {
  margin-top: 20px;

  // background-color: #f5f5f5;
  .boxone {
    background-color: #fff;
    margin-bottom: 20px;

    span {
      display: flex;
      justify-content: flex-end;
      color: #999999;
      text-decoration: none;
      padding: 20px 20px 0px 0px;

      &:hover {
        cursor: pointer;
      }
    }

    i {
      transform: translateY(1px);
    }

    h3 {
      transform: translateY(-40px);
      font-size: 28px;
      margin: 0;
      color: #666;
      font-weight: 400;
      text-align: center;
      line-height: 100px;
    }

    p {
      margin: 0;
      text-align: center;
      color: #999;
      font-size: 20px;
      transform: translateY(-60px);
    }

    .vessel {
      margin-left: 70px;
      transform: translateY(-20px);

      .boxtwo {
        display: inline-block;
        text-align: center;
        width: 220px;
        height: 300px;
        transition: all 0.5s;

        &:hover {
          transform: translateY(-5px);
          box-shadow: 0 20px 80px rgba(48, 49, 51, 0.15);
          cursor: pointer;
        }

        img {
          margin: 0 auto;
          padding-top: 20px;
          height: 160px;
          width: 160px;
        }

        p {
          margin: 0 auto;
          text-align: center;
          font-size: 16px;
          color: black;
          padding-top: 70px;
          width: 160px;
          /* 有限的空间才能有溢出的可能 */
          overflow: hidden;
          -webkit-line-clamp: 1;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          word-break: break-all;
          line-break: anywhere;
        }

        p:nth-child(3) {
          font-size: 14px;
          color: #999;
          padding-top: 8px;
        }

        p:last-child {
          color: #cf4444;
          font-size: 20px;
          padding-top: 10px;
        }
      }
    }
  }
}
</style>
